<?php
namespace Index\Controller;
use Think\Controller;
use Think\Model;


class IndexController extends Controller {
    public function index(){
    	// config表记录着基本信息   
    	$config = D('config')->select();

        //配置信息(重新配置)
    	$record = $config[1]['value'];
    	$title = $config[2]['value'];
    	$logo = $config[3]['value'];
    	$desc = $config[5]['value'];
		$keywords = $config[6]['value'];
		$contact = $config[8]['value'];
		$phone = $config[9]['value'];
		$address = $config[10]['value'];
		$qq = $config[11]['value'];
		$qq1 = $config[12]['value'];
		$qq2 = $config[13]['value'];
		
		// 注册与登入
        $_name = cookie('name');

        $name = D('users')->where(array('user_name'=>$_name))->find();

        $name = $name['user_name'];

        if(md5($_name) == md5($name)){
                $user_name = $_name;
            }else{
                $this->error('非法操作!');
        }
        
        //轮播图
        $banner = D('ad')->where('enabled','1')->order('orderby asc')->select();
		
		// 新闻类型(杰匠企业,公司新闻)
        $newsclass = D('article_cat')->field('cat_id,cat_name,cat_desc,photo')->order('sort_order')->limit(2)->select(); 
		// 12-12 未来要做的是公司新闻片问题
        foreach ($newsclass as $v) {
            $newsid[] = $v['cat_id'];
        }

        $news_id = $newsid[0];
        $dt_id = $newsid[1];
		
        $news = D('article')->where('cat_id='.$news_id)->where(array('is_open'=>1))->select();

        $dt = D('article')->where('cat_id='.$dt_id)->where(array('is_open'=>1))->select();

           $contents = D('article_cat  as  a')->join('ty_article  as  b  on b.cat_id = a.cat_id')->where('is_open','1')->select();

           $content = $contents[0]['content'];

		// 公司新闻
           $news = array();
           foreach ($contents as $k => $v) {
               if($v['cat_id'] == 2){
                   $news[] = $v;
               }
           }
		// 行业动态
           $dt = array();
           foreach ($contents as $k => $v) {
               if($v['cat_id'] == 3){
                    $dt[] = $v;
               }
           } 
		
		// 订单号码
        $order = D('order')->field('order_sn,consignee')->select();
		//合作伙伴图片的显示     东
        //订单总数 
        $order_base = D('order_base');
        $basebrr = $order_base ->select();
        $base = $basebrr[0]['base'];
        $counts = D('order')->count();
        $counts =  $base + $counts;
		$partners = D('partners');
		$partnersarr = $partners ->select();
		foreach($partnersarr as $k => $v){
			$v=substr($v['img'],1);
			$partnersarr[$k] = $v;
		}
		//服务内容的显示   东
		$service = D('service_content');
		$servicearr = $service ->select();
		$service_content = array();
		foreach ($servicearr as $k => $v) {
				$service_content[$k] = $v;
				$service_content[$k]['img'] = substr($v['img'], 1);
			}
//杰匠企业的显示   东
		$jj_enterprise = D('jj_enterprise');
		$jj_enterprise = $jj_enterprise ->select();
		$jjenterprise = array();
		foreach ($jj_enterprise as $k => $v) {
				$jjenterprise[$k] = $v;
				$jjenterprise[$k]['img'] = substr($v['img'], 1);
			}
//杰匠企业的显示   东
		$jj_park= D('jj_park');
		$jj_parkarr = $jj_park ->select();
		$jjpark = array();
		foreach ($jj_parkarr as $k => $v) {
				$jjpark[$k] = $v;
				$jjpark[$k]['img'] = substr($v['img'], 1);
			}
		// 将所有的方法 一次性输出到模板
    	$this->assign(array(
            'record'=>$record,
    		'banner'=>$banner,
    		'title'=>$title,
    		'logo'=>$logo,
    		'desc'=>$desc,
    		'keywords'=>$keywords, 
    		'contact'=>$contact,
    		'phone'=>$phone,
    		'address'=>$address,
    		'qq'=>$qq,
    		'qq1'=>$qq1,
    		'qq2'=>$qq2,
            'user_name'=>$user_name,
            'content'=>$content, 
            'news'=>$news,
            'dt'=>$dt,
            'order'=>$order,
         'partnersarr'=>$partnersarr, 
        'service_content' => $service_content,
         'jjenterprise' => $jjenterprise,
         'jjpark' => $jjpark,
            'newsclass'=>$newsclass,
            'counts'=>$counts
	));
    	$this->display();
    }
	
	// 新闻页面
	public function news($cat_id,$art_id){
    	
		$article = D('article');
		
		$content = $article->field('content,title')->where("article_id = '$art_id' AND cat_id = '$cat_id'")->select();
		
		$this->assign('content',$content);
				
    	$this->display();
    }

}

